//
//  ViewController.m
//  03-UIResponder
//
//  Created by 韩旭 on 16/7/18.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "ViewController.h"
#import "TouchView.h"
@interface ViewController ()

@end

@implementation ViewController
//
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    TouchView *touch = [[TouchView alloc] initWithFrame:CGRectMake(10, 0, 200, 200)];
    touch.backgroundColor = [UIColor redColor];
    [self.view addSubview:touch];
    //1. 响应者链
    //    触摸TouchView时
    //    检查顺序 ：从硬件 -> Appdelegate -> UIApplication->UIWindow -> UIViewController -> self.view -> TouchView
    //    响应顺序：TouchView -> self.view -> UIViewController -> UIWindow -> UIApplication -> Application -> null
    //    如果所有的响应者都无法响应时间, 则这个时间会被舍弃
    //    两种检测响应者的方法
    //    1. Category 实现 touchBegin的方法
    //    2. nextResponder
    //   例：
//   1.响应者不要出边界, 不边界的响应者无法响应
//   判断当前的点，在谁的范围内
//    用这个方法 返回值是个BOOL类型[touch pointInside:CGPointMake(10, 10) withEvent:nil]
    NSLog(@"%@", [touch pointInside:CGPointMake(10, 10) withEvent:nil] ? @"YES" : @"NO");
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(20, 20, 50, 50);
    button.backgroundColor = [UIColor yellowColor];
    [touch addSubview:button];
    [button addTarget:self action:@selector(button:)forControlEvents:UIControlEventTouchUpInside];
    //    touch.userInteractionEnabled = NO;
//    2. Button 的点击方法如何实现
//    button 点击效果通过, UIResponder对应的方法实现的
//    3. pointInside重写, 实现失去响应能力（return NO）
}

- (void)button:(UIButton *)btn {
    NSLog(@"%@", btn);
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    NSLog(@"class------------%@", NSStringFromClass(self.class));  NSLog(@"-----%s", __func__);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
